﻿using Microsoft.AspNetCore.Mvc;
using Swashbuckle.AspNetCore.Annotations;
using System;
using System.Threading.Tasks;
using VisionCloud.Domain.Common;
using VisionCloud.Domain.DtoModel.Applet.RequestDto;
using VisionCloud.Domain.DtoModel.Applet.ResponseDto;
using VisionCloud.Domain.Filters;
using VisionCloud.Service.Applet;

namespace VisionCloud.Api.Controllers.Applet
{
    /// <summary>
    /// 用户相关
    /// </summary>
    [SystemModule("小程序模块")]
    [ApiAuthorize(PolicyEnum.RequireRolePermission)]
    [ApiVersion("1.0")]
    [Route("api/applet/[controller]/[Action]")]
    [ApiExplorerSettings(GroupName = "小程序模块")]
    public class UserController : ApiBaseController
    {
        public UserService UserService { get; set; }

        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        [HttpGet]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<UserInfoDto>))]
        public async Task<ApiResult> GetCurUserInfo() => await TryCatchAsync(UserService.GetCurUserInfo());

        /// <summary>
        /// 分页获取当前用户下所有的设备
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<DeviceInfosDto>))]
        public async Task<ApiResult> GetCurUserDevices(PageRequest condition) => await TryCatchAsync(UserService.GetCurUserDevices(condition));

        /// <summary>
        /// 更新设备详细地址
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<DateTime>))]
        public async Task<ApiResult> UpdateDeviceAddress(DeviceLocationDto deviceLocation) => await TryCatchAsync(UserService.UpdateDeviceAddress(deviceLocation));

        /// <summary>
        /// 根据地理坐标获取位置描述
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [SwaggerResponse(0, "获取详情数据的字段：Result", typeof(ApiResultBase<AddressInfo>))]
        public async Task<ApiResult> GetAddress(LocationDto locaton) => await TryCatchAsync(UserService.GetAddress(locaton));
    }
}